﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace hozoroghiab
{
    public partial class editerealse : Form
    {
        string id, employe, family, begintime, endtime, code, date,totalday;
        sql sqlquery;
        public editerealse(sql s, string id, string employe, string family, string date, string begintime, string endtime,string totalday, string code)
        {
            InitializeComponent();
            sqlquery = s;
            this.id = id;
            this.employe = employe;
            this.family = family.Trim();
            this.date = date;
            this.begintime = begintime;
            this.endtime = endtime;
            this.totalday = totalday;
            this.code = code;
        }

        private void editerealse_Load(object sender, EventArgs e)
        {
            nametextbox.Text = employe;
            familytextbox.Text = family;
            codetextbox.Text = code;
            checkBox1.Checked = Convert.ToBoolean(totalday);
            beginhour.Value = int.Parse(begintime.Substring(0, begintime.IndexOf(":")));
            beginmin.Value = int.Parse(begintime.Substring(begintime.IndexOf(":") + 1, begintime.Length - begintime.IndexOf(":") - 1));
            endhour.Value = int.Parse(endtime.Substring(0, endtime.IndexOf(":")));
            endmin.Value = int.Parse(endtime.Substring(endtime.IndexOf(":") + 1, endtime.Length - endtime.IndexOf(":") - 1));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sqlquery.open();
            string t = checkBox1.Checked ? "1" : "0";
            sqlquery.ExecuteNonQuery("UPDATE vacation SET year=" + persianDateTimePicker.Value.Year.ToString() + ",month=" + persianDateTimePicker.Value.Month.ToString() + ",day=" + persianDateTimePicker.Value.Day.ToString() + ",code=" + codetextbox.Text + ",beginhour=" + beginhour.Value + ",beginmin=" + beginmin.Value + ",endhour=" + endhour.Value + ",endmin=" + endmin.Value + ",totalday=" + t + " WHERE id=" + id);
            sqlquery.close();
            Close();
        }
    }
}
